package servlet;

import com.alibaba.fastjson.JSONObject;
import service.schooltreasure_teacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "chachongServlet", value = "/chachongServlet")
public class chachongServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        schooltreasure_teacherService schooltreasure_teacherService=new schooltreasure_teacherService();
        int i = 0;
        try {
            String userName=req.getParameter("userName");
            i=schooltreasure_teacherService.selectUserName(userName);
        } catch (ClassNotFoundException | SQLException throwables) {
            throwables.printStackTrace();
        }
        PrintWriter printWriter=resp.getWriter();
        JSONObject JSONObject=new JSONObject();
        JSONObject.put("hang",i);
        printWriter.print(JSONObject);
        printWriter.flush();
        printWriter.close();

    }



}
